package com.ijiuchuang.jc_localization.view.adapter;

import android.content.Context;
import android.view.View;

import com.ijiuchuang.jc_localization.R;
import com.ijiuchuang.jc_localization.app.Config;
import com.ijiuchuang.jc_localization.bean.cache.DeviceListCache;
import com.ijiuchuang.jc_localization.bean.lite.Tag;
import com.ijiuchuang.jc_localization.tools.adapter.ViewHolder;
import com.ijiuchuang.jc_localization.tools.adapter.recyclerview.CommonAdapter;

import java.util.List;

/**
 * Created by Veev on 2016/6/13
 *
 * @link 384506557@qq.com
 */
public class DeviceListRecyclerAdapter extends CommonAdapter<Tag> {

    public DeviceListRecyclerAdapter(Context context, int layoutId, List<Tag> datas) {
        super(context, layoutId, datas);
    }

    @Override
    public void convert(final ViewHolder holder, final Tag tag) {
        holder.setText(R.id.recycler_item_device_list_text_mac, tag.getMac());
        holder.setText(R.id.recycler_item_device_list_text_name, tag.getName());
        holder.setChecked(R.id.recycler_item_device_list_switch_isShow, tag.isShow());
        holder.setOnClickListener(R.id.recycler_item_device_list_switch_isShow, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tag.setShow(holder.isChecked(R.id.recycler_item_device_list_switch_isShow));
                DeviceListCache.getInstance().setShow(tag.getMac(), holder.isChecked(R.id.recycler_item_device_list_switch_isShow));
                Config.liteOrm.update(tag);
            }
        });
    }
}
